use LWP::Simple;
use warnings;
use strict;
# Initializing files
open LOCATION, "> D:/prelex2013/location2.txt" or die "Problem: $!";
close LOCATION;
# Initializing variables
our $filecount=0;
open ID, "< D:/prelex2013/searchresults/DOSID2013.dat" or die "$!";
our @ID=<ID>;
close (ID);
foreach my $ID (@ID) {
      my $url ="http://ec.europa.eu/prelex/detail_dossier_real.cfm?CL=en&DosId="."$ID";
      my $content_full=get($url);
      if ($content_full=~/(COM|SEC)&nbsp;\(([0-9]{4})\)&nbsp;([0-9]{1,4})(.{5})/) {
           our $proposal;
           our $filename;
           our $d_type=$1;
           our $d_year=$2;
           our $d_number=$3;
           our $d_subnumber=$4;
           if ($d_subnumber=~/\s-\s([0-9]{1,2})/) {$d_subnumber=$1;} else {$d_subnumber='';}
           if ($d_subnumber ne '') {$proposal="$d_type "."\($d_year\)"." $d_number"." - $d_subnumber";}
                else {$proposal="$d_type "."\($d_year\)"." $d_number";}
           if ($d_subnumber ne '') {$filename="$d_type"."_$d_year"."_$d_number"."_$d_subnumber"."\.html";}
                else {$filename="$d_type"."_$d_year"."_$d_number"."\.html";}
           our $filename2="$d_type"."_$d_year"."_$d_number"."_$d_subnumber"."\.txt";
           print "Proposal\: $proposal \n";
           open DATASHEET, "> D:/prelex2013/datasheets/$d_year/$filename" or die "Problem: $!";
           print DATASHEET $content_full;
           close DATASHEET;
           open LOCATION, ">> D:/prelex2013/location2.txt" or die "Problem: $!";
           print LOCATION "D:/prelex2013/datasheets/$d_year/$filename\n";
           close LOCATION;
           $filecount++;
           }
     }
print "Files insgesamt\t$filecount\n";